﻿Ext.namespace("Swfu");
Ext.namespace("Swfu.BackMgr");

Swfu.BackMgr.VehicleMgr = Ext.extend(Ext.grid.GridPanel, {
    initComponent: function () {
        var ddlDeptVehi = new Ext.form.TreeField({
            id: 'treeDeptVehi', name: 'treeDeptVehi',
            dataUrl: '/dept.mvc/DeptTreeByEmp',
            syncParams: 'controllerName=Vehicle',
            listHeight: 250, width: 150
        });
        //var sm = new Ext.grid.CheckboxSelectionModel({ singleSelect: true });
        var fm = Ext.form;

        var cm = new Ext.grid.ColumnModel([
            {
                header: "表单编号",
                dataIndex: 'FormNo'
            }, {
                header: "预计开始时间",
                dataIndex: 'PreStartTime'
            }, {
                header: "预计结束时间",
                dataIndex: 'PreEndTime'
            }, {
                header: "申请人",
                dataIndex: 'EmpName'
            }, {
                header: "申请车辆",
                dataIndex: 'Vehicle'
            }, {
                header: "申请原因",
                dataIndex: 'Cause'
            }, {
                header: '签核状态',
                dataIndex: 'StatusId',
                renderer: getStatusName
            }, { header: "操作", dataIndex: 'FormNo', width: 130, renderer: function (value, a, reader, c, d, ds) {
                var links = [];
                var hasSign = reader.data.StatusId != "0";
                links.push('<a href="#" onclick="return SignWin(\'' + value + '\',true,' + hasSign + ');">查看</a>');
                if ((Cookies.get("empId") == "708" || Cookies.get("empId") == "187") && reader.data.StatusId == 1) {
                    links.push('<a  href="#" onclick="SignnoPass(\'' + value + '\');" >退件</a>');
                }
                if (reader.data.EmpId == Cookies.get("empId") && "0,3".indexOf(reader.data.StatusId) >= 0) {
                    links.push('<a href="#" onclick="var url =\'VehicleEdit.aspx?formNo=' + value + '\';window.showModalDialog(url, window, \'dialogWidth=850px;dialogHeight=550px;status=no;help=no;resizable=yes;\');Ext.getCmp(\'VehicleMgr\').getStore().reload();">编辑</a>');
                }
                if (reader.data.StatusId == "1" && reader.data.CheckEmpId == Cookies.get("empId")) {
                    links.push('<a href="#" onclick="return SignWin(\'' + value + '\',true,true);">签核</a>');
                }
                if (reader.data.EmpId == Cookies.get("empId") && "0,3".indexOf(reader.data.StatusId) >= 0) {
                    links.push('<a href="#" onclick="return delForm(\'' + value + '\');">删除</a>');
                }
                //销单申请,排除不需要销单和销单不用审批的单据
                if (reader.data.StatusId == "2" && "2".indexOf(Cookies.get("empId")) >= 0 && "Vehi".indexOf(value.substr(5, 4)) >= 0) {//用车单由司机销单
                    links.push('<a href="#" onclick="return SignWin(\'' + value + '\',false,false);">销单</a>');
                } else if (reader.data.StatusId == "2" && reader.data.EmpId == Cookies.get("empId") && "Week,Vehi,Invi".indexOf(value.substr(5, 4)) == -1) {
                    links.push('<a href="#" onclick="return SignWin(\'' + value + '\',false,false);">销单申请</a>');
                }
                if (reader.data.StatusId == "4" && reader.data.CheckEmpId == Cookies.get("empId")) {
                    links.push('<a href="#" onclick="return SignWin(\'' + value + '\',true,true);">销单审批</a>');
                }
                return links.join("&nbsp;");
            }
            }
		]);
        var reader = new Ext.data.JsonReader({
            totalProperty: 'totalCount', //分页使用
            root: 'data',
            autoLoad: true,
            fields: [{
                name: 'FormNo'
            }, {
                name: 'PreStartTime'
            }, {
                name: 'PreEndTime'
            }, {
                name: 'EmpId'
            }, {
                name: 'EmpName'
            }, {
                name: 'Vehicle'
            }, {
                name: 'Cause'
            }, {
                name: 'StatusId'
            }, {
                name: 'CheckEmpId'
            }]
        });
        var ds = new Ext.data.Store({
            scopte: this,
            id: 'vehicleDS',
            url: '/Vehicle.mvc/Find',
            reader: reader
        });
        ds.on('beforeload', function (thiz, options) {
            Ext.apply(thiz.baseParams, { idStr: Ext.getCmp('treeDeptVehi').getValue() });
            //这个也行
            //gridStore.baseParams["comboValue"]=Ext.getCmp("input").getValue();
        });

        Ext.apply(this, {
            id: 'VehicleMgr', plain: true, layout: 'fit', border: false,
            cm: cm, frame: true, store: ds, loadMask: true,
            tbar: [{
                text: "添加",
                tooltip: "添加新的信息",
                iconCls: "addicon",
                handler: function () {
                    var url = 'VehicleAdd.aspx';
                    var retVal = window.showModalDialog(url, window, 'dialogWidth=850px;dialogHeight=550px;status=no;help=no;resizable=yes;');
                    if (retVal != undefined && retVal.indexOf('Form') >= 0) {
                        url = 'VehicleEdit.aspx?formNo=' + retVal;
                        window.showModalDialog(url, window, 'dialogWidth=850px;dialogHeight=550px;status=no;help=no;'); //检测数据更改>刷新?
                        ds.reload();
                    }
                }
            }, '-', {
                text: "重新加载数据",
                iconCls: 'icon-redo',
                handler: function () {
                    ds.reload();
                } .createDelegate(this)
            }, '->', {
                xtype: 'tbtext',
                text: '部门:'
            }, ddlDeptVehi, '-', {
                text: "查询",
                iconCls: 'icon-search',
                handler: function () { ds.reload(); }
            }],

            //分页
            bbar: new Ext.PagingToolbar({
                pageSize: 20,
                store: ds,
                displayInfo: true,
                displayMsg: '显示第 {0} 条到 {1} 条记录，共 {2} 条',
                emptyMsg: '无记录',
                hidden: false
            })
        });
        Swfu.BackMgr.VehicleMgr.superclass.initComponent.apply(this, arguments);
        ds.load({ params: { start: 0, limit: 20} });
    }
});